package charazay.tool.managers.files;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class FileManager {
	private static  final   String      SOFTWARE_DIR             = System.getProperty("user.home") + "/.charazayorganizer/";
	public  static  final   String      CONF_FILE                = SOFTWARE_DIR + "conf.properties";

	public static  final   String      PLAYERS_DIR              = SOFTWARE_DIR + "players/";
	public static  final   String      MATCHES_DIR              = SOFTWARE_DIR + "matches/";
	
	public	static	void	initDirectories(){
		createDirectoryIfNeeded(SOFTWARE_DIR);
		createDirectoryIfNeeded(PLAYERS_DIR);
		createDirectoryIfNeeded(MATCHES_DIR);
		initConfFile(CONF_FILE);
	}
	
	public	static	void	createDirectoryIfNeeded(String directoryName){
		//System.out.println(directoryName);
		File				dir = new File(directoryName);

		if (!dir.exists()){
			dir.mkdir();
		}
	}
	
	public	static	void	initConfFile(String fileName){
		
		File				file = new File(fileName);

		if (!file.exists()){
			try {
				file.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
			
			Properties prop = new Properties();
			prop.setProperty("language","fr");
			prop.setProperty("country","FR");
			
			try {
		        prop.store(new FileOutputStream(fileName), null);
		    } catch (IOException e) {
		    	e.printStackTrace();
		    }
		}
	}
	
}
